﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Ewts.ashx
{
    /// <summary>
    /// basicData 的摘要说明
    /// </summary>
    public class basicData : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string cum = "";
            if (context.Request["cumcode"] != null && context.Request["cumcode"].ToString().Trim()!="")
            {
                int id = int.Parse(context.Request["id"].ToString());
                cum = CodeISExits(context.Request["cumcode"].ToString().Trim(),id);
            }
            else if (context.Request["proid"] != null && context.Request["type"] != null)
            {
                int proid = int.Parse(context.Request["proid"].ToString().Trim());
                int type = int.Parse(context.Request["type"].ToString().Trim());
                //取客户名称
                cum = GetCumName(proid,type);
            }
            else if (context.Request["cumtype"] != null && context.Request["cumid"]!=null)
            {
                string cumtype = context.Request["cumtype"].ToString().Trim();

                int cumid = int.Parse(context.Request["cumid"].ToString().Trim());

                DataLib.BLL.Cumtomer bll = new DataLib.BLL.Cumtomer();
                DataLib.Model.Cumtomer model = new DataLib.Model.Cumtomer();
                model = bll.GetModel(cumid);
                if (cumtype == "all") 
                {
                    cum = model.companyname;
                }
                else if (cumtype == "short")
                {
                    cum = model.shortname;
                }
                else if (cumtype == "code")
                {
                    cum = model.customercode;
                }

            }

            context.Response.Write(cum);
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }

        /// <summary>
        ///
        /// </summary>
        /// <param name="cumcode"></param>
        /// <returns> 1是存在 0是不存在</returns>
        public string CodeISExits(string cumcode,int id)
        {
            string flag = "1";
            DataLib.BLL.Cumtomer bll = new DataLib.BLL.Cumtomer();
            if (bll.CodeIsExits(cumcode,id))
            {
                flag = "1";
            }
            else
            {
                flag = "0";
            }
            return flag;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="proid"></param>
        /// <param name="type">1 cjo 2 print 3 lab</param>
        /// <returns></returns>
        public string GetCumName(int proid, int type)
        {
            string cum = "";
            cum = new DataLib.BLL.Project().GetCusNameByProid(proid, type);
            return cum;
        }
    }
}